import { _decorator, Button, Component, Game, Label, Node, ProgressBar, tween } from 'cc';
import { UIBase } from './UIBase';
import { UIManager } from './UIManager';
import { Constants, Orientation } from '../game/Constants';
import { EventListener } from '../core/EventListener';
import { BeginItem } from './item/BeginItem';
import { UIGame } from './UIGame';
import { EnemyManger } from '../actor/EnemyManger';
import { AudioManager } from '../game/AudioManager';
const { ccclass, property } = _decorator;

@ccclass('UIBegin')
export class UIBegin extends UIBase {
    @property(BeginItem) landscapeNode: BeginItem = null;
    @property(BeginItem) portraitNode: BeginItem = null;
    private isHide: boolean = false;

    start() {
        this.initOrientationUI();
        EventListener.on(Constants.Event_OrientationChange, this.initOrientationUI, this);
        this.landscapeNode.timeOutCb = this.hideUI.bind(this);
        this.portraitNode.timeOutCb = this.hideUI.bind(this);
    }

    private hideUI() {
        if (this.isHide)
            return;
        this.isHide = true;
        this.onHide();
        UIGame.Instance.onShow();

        // 开始刷怪
        EnemyManger.Instance.autoCreateEnemy(1);

        AudioManager.Instance.canPlay = true;
        AudioManager.Instance.playBgm(true);
    }

    private initOrientationUI() {
        if (UIManager.Instance.orientation === Orientation.Landscape) {
            this.landscapeNode.node.active = true;
            this.portraitNode.node.active = false;
        } else {
            this.landscapeNode.node.active = false;
            this.portraitNode.node.active = true;
        }
    }
}